package com.meilai.project.controller.web.business.sale;


import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.dto.business.sale.BillSaleGroupDTO;
import com.meilai.project.dto.business.saleOrder.SaleQueryGroupDTO;
import com.meilai.project.service.business.sale.BillSaleGroupService;
import com.meilai.project.vo.business.sale.BillSaleGroupVO;
import com.meilai.project.vo.business.sale.BillSaleVO;
import com.meilai.project.vo.business.sale.ContractCustomerVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 销售分组表 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-12-05
 */
@RestController
@RequestMapping("api/web/bill_sale_group")
public class BillSaleGroupController {

    @Autowired
    private BillSaleGroupService billSaleGroupService;

    @PostMapping("/relation")
    @ApiOperation(value = "关联组别")
    public ApiResult<Boolean> relation(@RequestBody BillSaleGroupDTO dto) {
        return ApiResult.ok(billSaleGroupService.relation(dto));
    }

    @GetMapping("/list")
    @ApiOperation(value = "分组列表")
    public ApiResult<List<BillSaleGroupVO>> list() {
        return ApiResult.ok(billSaleGroupService.selectList());
    }

    @GetMapping("/list_by_account_received_id")
    @ApiOperation(value = "根据到款id，查询分组列表")
    public ApiResult<List<BillSaleGroupVO>> listByAccountReceivedId(@RequestParam(value = "acId", required = false) Long acId) {
        return ApiResult.ok(billSaleGroupService.selectListByAccountReceivedId(acId));
    }

    @PostMapping("/list_by_dto")
    @ApiOperation(value = "查询分组列表")
    public ApiResult<List<BillSaleGroupVO>> listByAccountReceivedId(@RequestBody SaleQueryGroupDTO dto) {
        return ApiResult.ok(billSaleGroupService.selectListByDto(dto));
    }

    @GetMapping("/sale/list")
    @ApiOperation(value = "获取销售单数据（未分组的）")
    public ApiResult<List<BillSaleVO>> saleList(@RequestParam(value = "customer_id", required = false) Long customer_id) {
        return ApiResult.ok(billSaleGroupService.saleList(customer_id));
    }

    @GetMapping("/sale/list-in-group")
    @ApiOperation(value = "根据分组id，获取销售单数据")
    public ApiResult<List<BillSaleVO>> saleListInGroup(@RequestParam(value = "group_id", required = false) Long group_id) {
        return ApiResult.ok(billSaleGroupService.saleListInGroup(group_id));
    }

    @GetMapping("/getContractAndCustomerByGroupId")
    public ApiResult<ContractCustomerVO> getContractAndCustomerByGroupId(@RequestParam("group_id") Long group_id) {
        return ApiResult.ok(billSaleGroupService.getContractAndCustomerByGroupId(group_id));
    }
}
